const app = getApp()

Page({
    data: {
        tab: "小心，疫情期间蝴蝶效应",
        people: 94587,
        // testNum: '1758',
        PeopleNum: '9.5',
        picture: '',
        describe: "",
        openid: '',
        timuid: '',
        arrayList: [
            {
              information: "小心，疫情期间蝴蝶效应",
              detail:"疫情远远还未结束，持续性影响将会改变你的生活"
            }
          ]
    },
    onLoad: function (options) {
      tt.setNavigationBarColor({
        frontColor: "#000000",
        backgroundColor: "#ffffff",
        success(res) {
          console.log(res);
        },
        fail(res) {
          console.log("setNavigationBarColor调用失败");
        }
      });

      let timuid = options.timuid || "";
      console.log(timuid);
      var that = this;
      let tap = tt.request({
        url: 'https://dycps.aikeai.group/testService/findTestPage', // 目标服务器url
        data:{
          timuid: timuid
        },
        success: (res) => {
          console.log(res,"问卷");
          that.timuid = res.data[0].timuid;
          that.setData({
            tab: res.data[0].name,
            people: res.data[0].count,
            html: res.data[0].html,
            describe: res.data[0].shortDescribe,
            picture: res.data[0].introPicture
          });
        }
      });

      let hotTest = tt.request({
        url: 'https://dycps.aikeai.group/testService/findHotTest', // 目标服务器url
        success: (res) => {
          console.log(res,"hotTest");
          that.setData({
            arrayList:  res.data
          })
        }
      });
      console.log("1111");
      try {
        const openid = tt.getStorageSync("openid");
        console.log(openid,'openid1');
        that.openid = openid;
        // if (!openid) {
        //   console.log(openid,'openid2')
        // }
      } catch (error) {
        console.log('getStorageSync调用失败');
      }
    
    },
    quickTest: function(e){
      console.log(e);
      console.log(e.target.id,"e.target.timuid")
      let timuid = e.target.id;
      tt.navigateTo({
        url: `/pages/testing/testing?timuid=${timuid}`,
        success(res) {
          console.log(`${res}`);
        },
        fail(res) {
          console.log(`navigateTo调用失败`);
        }
      });
    
    },
    quickT: function() {
      var that = this;
      console.log(that.openid,'that.openid');
      console.log(that.timuid,'that.timuid');
   
      // tt.request({
      //   url: 'https://dycps.aikeai.group/orderService/createOrderInfo?openid='+that.openid, // 目标服务器url
      //   method: "post",
      //   header: {
      //     "content-type": "application/json"
      //   },
      //   // data: {
      //   //   openid: that.openid
          
      //   // },
      //   success: (res) => {
      //     console.log(res,"创建订单")
      //     console.log(res.data.app_id,"创建订单1")
      //     tt.pay({
      //       orderInfo: res.data,
      //       service: 4,
      //       // _debug: 1,
      //       // getOrderStatus(res) {
      //       //   console.log(res,"status")  
      //       // },
      //       payChannel: {
      //         default_pay_channel: "alipay" // wx || alipay
      //       },
      //       success(res) {
      //         if (res.code == 0) {
      //           console.log(res,"创建订单成功")

                tt.navigateTo({
                  url: `/pages/topic/topic?timuid=${that.timuid}`,
                  success(res) {
                    console.log(`${res}`);
                  },
                  fail(res) {
                    console.log(`navigateTo调用失败`);
                  }
                });
              
          //       // 支付成功处理逻辑，只有res.code=0时，才表示支付成功
          //       // 但是最终状态要以商户后端结果为准
          //     }
          //   },
          //   fail(res) {
          //     // 调起收银台失败处理逻辑
          //     console.log(res,"失败");
          //   }
          // });

        // }
      // });
    }
})